﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace GeneralServices.Model
{

    /// <summary>
    /// Interface définissant les méthodes les plus utilisés pour implémenter une couche DAO.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IRepository<T, TypeDTO>
        where T : class
        where TypeDTO : IDTO
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        TypeDTO First(Func<TypeDTO, bool> predicate);

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        IEnumerable<TypeDTO> All();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        TypeDTO Find(object[] key);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        TypeDTO Find(Predicate<TypeDTO> predicate);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        IEnumerable<TypeDTO> Filter(Func<TypeDTO, bool> predicate);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        bool Contains(Func<TypeDTO, bool> predicate);

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        TypeDTO SingleOrDefault(Func<TypeDTO, bool> predicate);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        T Update(TypeDTO entity, Boolean commit = false);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Delete(TypeDTO entity, Boolean commit = false);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        int Delete(Func<TypeDTO, bool> predicate, Boolean commit = false);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        T Insert(TypeDTO entity, Boolean commit = false);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        T Save(TypeDTO t);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="TObject"></param>
        void Refresh(TypeDTO TObject);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        void RollBack(TypeDTO entity);

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        IDTO CreateEmpty();

        /// <summary>
        /// 
        /// </summary>
        void RollBackAll();
    }
}
